var app = getApp();
Page({
	data: {
		filterId: 1,
		address: '北京',
		banners: [
			{
				id: 1,
				img: 'http://oss.zhuantou.tv/lessonPic/old/banner1.png',
				url: '',
				name: 'help'
			}
		],
		icons: [
			[
				{
					id: 1,
					img: '/imgs/index/icon_1.jpg',
					name: '点餐',
					url: ''
				}
			],[]
		],
		shops: app.globalData.shops
	},
  onLoad: function () {
    this.setData({
      address: '华北电力大学'
    });
	},
	onShow: function () {
	},
	onScroll: function (e) {
		if (e.detail.scrollTop > 100 && !this.data.scrollDown) {
			this.setData({
				scrollDown: true
			});
		} else if (e.detail.scrollTop < 100 && this.data.scrollDown) {
			this.setData({
				scrollDown: false
			});
		}
	},
	tapSearch: function () {
		wx.navigateTo({url: 'search'});
	},
	tapOrder: function () {
		wx.navigateTo({ url: '/page/shop/shop?id=1' });
	},
	toNearby: function () {
		var self = this;
		self.setData({
			scrollIntoView: 'nearby'
		});
		self.setData({
			scrollIntoView: null
		});
	},
	tapFilter: function (e) {
		switch (e.target.dataset.id) {
			case '1':
				this.data.shops.sort(function (a, b) {
					return a.id > b.id;
				});
				break;
			case '2':
				this.data.shops.sort(function (a, b) {
					return a.sales < b.sales;
				});
				break;
			case '3':
				this.data.shops.sort(function (a, b) {
					return a.distance > b.distance;
				});
				break;
		}
		this.setData({
			filterId: e.target.dataset.id,
			shops: this.data.shops
		});
	},
	tapBanner: function (e) {
		var name = this.data.banners[e.target.dataset.id].name;
		console.log(e);
		wx.showModal({
			title: 'Help yourself!',
			content: '欢迎使用华电外卖！',
			showCancel: false
		});
	},
	onCall: function () {
		wx.makePhoneCall({
			phoneNumber: '010-61773299'
		})
	},
	onShareAppMessage: function () {
		return {
			title: '华电外卖',
			desc: '华电人自己的外卖平台!',
			path: '/page/index/index'
		}
	}
});

